/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SupplierPanel.java
 *
 * Created on 26-10-2011, 20:42:38
 */
package GUILager;
import ModelLager.SupplierP;
import ControlLager.SupplierPCTR;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JTable;
/**
 *
 * @author Jonas Kristensen
 */
public class SupplierPanel extends javax.swing.JPanel {

    private SupplierPCTR supCTR;
    /** Creates new form SupplierPanel */
    public SupplierPanel() {
        initComponents();
        supCTR = new SupplierPCTR();
        cityTextField.setEditable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        infoLabel = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        søgIDButton = new javax.swing.JButton();
        createSupplierButton = new javax.swing.JButton();
        updateSupplierButton = new javax.swing.JButton();
        deleteSupplierButton = new javax.swing.JButton();
        clearFieldsButton = new javax.swing.JButton();
        addressTextField = new javax.swing.JTextField();
        addressLabel = new javax.swing.JLabel();
        countryLabel = new javax.swing.JLabel();
        countryTextField = new javax.swing.JTextField();
        zipCodeLabel = new javax.swing.JLabel();
        cityLabel = new javax.swing.JLabel();
        cityTextField = new javax.swing.JTextField();
        phoneNoLabel = new javax.swing.JLabel();
        emailLabel = new javax.swing.JLabel();
        emailTextField = new javax.swing.JTextField();
        IDTextField = new javax.swing.JTextField();
        IDLabel = new javax.swing.JLabel();
        ListsPanel = new javax.swing.JPanel();
        SearchNameButton = new javax.swing.JButton();
        AllSuppliersButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        rydTableButton = new javax.swing.JButton();
        zipcodeTextField = new javax.swing.JTextField();
        phonNoTextField = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        statusLabel = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());

        infoLabel.setText("Information about suppliers");

        nameLabel.setText("Name:");

        søgIDButton.setText("Søg på ID");
        søgIDButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                søgIDButtonActionPerformed(evt);
            }
        });

        createSupplierButton.setText("Opret supplier");
        createSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createSupplierButtonActionPerformed(evt);
            }
        });

        updateSupplierButton.setText("Ændre supplier");
        updateSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateSupplierButtonActionPerformed(evt);
            }
        });

        deleteSupplierButton.setText("Slet supplier");
        deleteSupplierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteSupplierButtonActionPerformed(evt);
            }
        });

        clearFieldsButton.setText("Ryd felter");
        clearFieldsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearFieldsButtonActionPerformed(evt);
            }
        });

        addressLabel.setText("Address:");

        countryLabel.setText("Country:");

        zipCodeLabel.setText("Zipcode:");

        cityLabel.setText("City:");

        phoneNoLabel.setText("PhoneNo:");

        emailLabel.setText("Email:");

        IDLabel.setText("ID:");

        ListsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Flere resultater"));

        SearchNameButton.setText("Søg på navn");
        SearchNameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchNameButtonActionPerformed(evt);
            }
        });

        AllSuppliersButton.setText("Alle suppliers");
        AllSuppliersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AllSuppliersButtonActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Name", "Address", "Zipcode", "City", "Country", "PhoneNo", "Email", "SupplierID"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        rydTableButton.setText("Ryd tabel");
        rydTableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rydTableButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ListsPanelLayout = new javax.swing.GroupLayout(ListsPanel);
        ListsPanel.setLayout(ListsPanelLayout);
        ListsPanelLayout.setHorizontalGroup(
            ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ListsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 713, Short.MAX_VALUE)
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addComponent(SearchNameButton)
                        .addGap(18, 18, 18)
                        .addComponent(AllSuppliersButton)
                        .addGap(18, 18, 18)
                        .addComponent(rydTableButton)))
                .addContainerGap())
        );
        ListsPanelLayout.setVerticalGroup(
            ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ListsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SearchNameButton)
                    .addComponent(AllSuppliersButton)
                    .addComponent(rydTableButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(infoLabel)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(addressLabel)
                                    .addComponent(countryLabel)
                                    .addComponent(zipCodeLabel)
                                    .addComponent(cityLabel)
                                    .addComponent(phoneNoLabel)
                                    .addComponent(emailLabel)
                                    .addComponent(IDLabel))
                                .addGap(6, 6, 6)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(IDTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cityTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(addressTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(zipcodeTextField)
                                        .addComponent(countryTextField))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(phonNoTextField)
                                        .addComponent(emailTextField))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(clearFieldsButton)
                                    .addComponent(deleteSupplierButton)
                                    .addComponent(updateSupplierButton)
                                    .addComponent(createSupplierButton)
                                    .addComponent(søgIDButton)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ListsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(10, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {IDTextField, addressTextField, cityTextField, countryTextField, emailTextField, nameTextField});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearFieldsButton, createSupplierButton, deleteSupplierButton, søgIDButton, updateSupplierButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ListsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(infoLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nameLabel)
                            .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(søgIDButton))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addressTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(createSupplierButton)
                            .addComponent(addressLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(countryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(updateSupplierButton)
                            .addComponent(countryLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(deleteSupplierButton)
                            .addComponent(zipcodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(zipCodeLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(clearFieldsButton)
                            .addComponent(cityLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(phonNoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(phoneNoLabel))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(emailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(emailLabel))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(IDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(IDLabel)))
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void clearFields()
    {
        nameTextField.setText("");
        addressTextField.setText("");
        countryTextField.setText("");
        zipcodeTextField.setText("");
        cityTextField.setText("");
        phonNoTextField.setText("");
        emailTextField.setText("");
        IDTextField.setText("");
        statusLabel.setText("");
    }
    
    private void clearTable(JTable table)
    {
        int rowCount = 0;
        while(rowCount < table.getRowCount())
        {
            clearColumn(table, rowCount);
            rowCount++;
        }
    }
    
    private void clearColumn(JTable table, int row)
    {
        int column = 0;
        int size = table.getColumnCount();
        while(column < size)
        {
            table.setValueAt(null, row, column);
            column++;
        }
    } 
    
    private void putValuesOnScreen(SupplierP supObj)
    {
        nameTextField.setText(supObj.getName());
        addressTextField.setText(supObj.getAddress());
        countryTextField.setText(supObj.getCountry());
        zipcodeTextField.setText(supObj.getZipCode());
        cityTextField.setText(supObj.getCity());
        phonNoTextField.setText(supObj.getPhoneNo());
        emailTextField.setText(supObj.getEmail());
        IDTextField.setText("" + supObj.getSupplierID());
    }
    
    private void søgIDButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_søgIDButtonActionPerformed
        try
        {
            
            if(IDTextField.getText().length() == 0)
            {
               statusLabel.setText("Indtast ID!");
            }
            else
            {
                int input = Integer.parseInt(IDTextField.getText().trim());
                SupplierP supObj = supCTR.findSupplierByID(input);
                if(supObj == null)
                {
                    statusLabel.setText("ID eksisterer ikke");
                }
                else
                {
                    clearFields();
                    putValuesOnScreen(supObj);
                }
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
            statusLabel.setText("Indtast gyldigt id");
        }
        
        
    }//GEN-LAST:event_søgIDButtonActionPerformed

    private void clearFieldsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearFieldsButtonActionPerformed
        clearFields();
    }//GEN-LAST:event_clearFieldsButtonActionPerformed

    private void createSupplierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createSupplierButtonActionPerformed
        try
        {
            if(nameTextField.getText().length() == 0 || addressTextField.getText().length() == 0 || countryTextField.getText().length() == 0 || zipcodeTextField.getText().length() == 0 || phonNoTextField.getText().length() == 0 || emailTextField.getText().length() == 0 || IDTextField.getText().length() == 0)
            {
                statusLabel.setText("UDFYLD alle felter");
            }
            else
            {
                String name = nameTextField.getText();
                String address = addressTextField.getText();
                String country = countryTextField.getText();
                String zipCode = zipcodeTextField.getText();
                
                String phoneNo = phonNoTextField.getText();
                String email = emailTextField.getText();
                int supplierID =Integer.parseInt(IDTextField.getText());
                
                supCTR.createSupplier(name, address, country, phoneNo, email, supplierID, zipCode, country);
                statusLabel.setText("Supplier oprettet!");
            }       
        }
        catch(NumberFormatException e)
        {
            statusLabel.setText("Indtast gyldig værdi som ID!");
            System.out.println(e.getMessage());
        }
        catch(SQLException e)
        {
            statusLabel.setText("ID FINDES/Postnummer ugyldigt");
            System.out.println(e.getMessage());
        }
        
        catch(Exception e)
        {
            statusLabel.setText("Fejl");
            System.out.println(e.getMessage());
        }
        
    }//GEN-LAST:event_createSupplierButtonActionPerformed

    private void updateSupplierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateSupplierButtonActionPerformed
          try
          {
            String name = nameTextField.getText();
            String address = addressTextField.getText();
            String country = countryTextField.getText();
            String zipCode = zipcodeTextField.getText();

            String phoneNo = phonNoTextField.getText();
            String email = emailTextField.getText();
            int supplierID =Integer.parseInt(IDTextField.getText());
            
            supCTR.updateSupplier(name, address, country, phoneNo, email, supplierID, zipCode);
            statusLabel.setText("Supplier opdateret");
          }
      
          catch(SQLException e)
          {
              System.out.println(e.getMessage());
              statusLabel.setText("Postnummer ugyldigt");
          }
          catch(Exception e)
          {
              System.out.println(e.getMessage());
              
          }
          
    }//GEN-LAST:event_updateSupplierButtonActionPerformed

    private void deleteSupplierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSupplierButtonActionPerformed
        try
        {
            int supplierID =Integer.parseInt(IDTextField.getText());
            if(supCTR.deleteSupplier(supplierID) == 1)
            {
                statusLabel.setText("Slettet");
            }
            else
            {
            statusLabel.setText("Supplier ikke fundet");
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
            statusLabel.setText("Du skal indtaste den rigtige ID");
        }
    }//GEN-LAST:event_deleteSupplierButtonActionPerformed

    private void AllSuppliersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AllSuppliersButtonActionPerformed
        clearTable(jTable1);
        ArrayList<SupplierP> supplier = supCTR.getAllSuppliers();
        int row = 0;
        for(SupplierP sup : supplier)
        {
            jTable1.setValueAt(sup.getName(), row, 0);
            jTable1.setValueAt(sup.getAddress(), row, 1);
            jTable1.setValueAt(sup.getZipCode(), row, 2);
            jTable1.setValueAt(sup.getCity(), row, 3);
            jTable1.setValueAt(sup.getCountry(), row, 4);
            jTable1.setValueAt(sup.getPhoneNo(), row, 5);
            jTable1.setValueAt(sup.getEmail(), row, 6);
            jTable1.setValueAt(sup.getSupplierID(), row, 7);
            row++;
        }

        
//        buildList(supplier);
    }//GEN-LAST:event_AllSuppliersButtonActionPerformed

    private void rydTableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rydTableButtonActionPerformed
        clearTable(jTable1);
    }//GEN-LAST:event_rydTableButtonActionPerformed

    private void SearchNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchNameButtonActionPerformed
        clearTable(jTable1);
        int row = 0;
        String name = nameTextField.getText();
        
        ArrayList<SupplierP> suppliers = supCTR.findSuppliersByName(name);
        for(SupplierP sup : suppliers)
        {
            jTable1.setValueAt(sup.getName(), row, 0);
            jTable1.setValueAt(sup.getAddress(), row, 1);
            jTable1.setValueAt(sup.getZipCode(), row, 2);
            jTable1.setValueAt(sup.getCity(), row, 3);
            jTable1.setValueAt(sup.getCountry(), row, 4);
            jTable1.setValueAt(sup.getPhoneNo(), row, 5);
            jTable1.setValueAt(sup.getEmail(), row, 6);
            jTable1.setValueAt(sup.getSupplierID(), row, 7);
            row++;
        }
    }//GEN-LAST:event_SearchNameButtonActionPerformed

//    private void buildList(ArrayList<SupplierP> supplier)
//    {   
//        jList1.setListData(empty);
//        String[] suppliers = new String[supplier.size()];
//        int index = 0;
//        for(SupplierP sup : supplier)
//        {
//            String name = sup.getName();
//            String address = sup.getAddress();
//            String country = sup.getCountry();
//            String phoneNo = sup.getPhoneNo();
//            String email = sup.getEmail();
//            int supplierID = sup.getSupplierID();
//            String zipcode = sup.getZipCode();
//            
//            if(name.length() < 15){
//                int length = name.length();
//                while (length < 20)
//               {
//                  name = name + "  ";
//                  length++;
//               }
//            }
//            suppliers[index] =(name + " " + address + " " + country + " " + supplierID);
//            index++;
//        }
//        jList1.setListData(suppliers);
//    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AllSuppliersButton;
    private javax.swing.JLabel IDLabel;
    private javax.swing.JTextField IDTextField;
    private javax.swing.JPanel ListsPanel;
    private javax.swing.JButton SearchNameButton;
    private javax.swing.JLabel addressLabel;
    private javax.swing.JTextField addressTextField;
    private javax.swing.JLabel cityLabel;
    private javax.swing.JTextField cityTextField;
    private javax.swing.JButton clearFieldsButton;
    private javax.swing.JLabel countryLabel;
    private javax.swing.JTextField countryTextField;
    private javax.swing.JButton createSupplierButton;
    private javax.swing.JButton deleteSupplierButton;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JTextField emailTextField;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JTextField phonNoTextField;
    private javax.swing.JLabel phoneNoLabel;
    private javax.swing.JButton rydTableButton;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JButton søgIDButton;
    private javax.swing.JButton updateSupplierButton;
    private javax.swing.JLabel zipCodeLabel;
    private javax.swing.JTextField zipcodeTextField;
    // End of variables declaration//GEN-END:variables
}
